import 'package:demo_proj01/pages/homepage.dart';
import 'package:demo_proj01/pages/hot_page.dart';
import 'package:demo_proj01/pages/my_page.dart';
import 'package:flutter/material.dart';

class TabPage extends StatefulWidget {
  const TabPage({super.key});

  @override
  State<StatefulWidget> createState() {
    return _TabPageState();
  }
}

class _TabPageState extends State<TabPage> {
  int curIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: curIndex,
        children: [Homepage(), HotPage(), MyPage()],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: curIndex,
        items: _barItemList(),
        onTap: (index) {
          // 点击切换页面
          curIndex = index;
          setState(() {});
        },
      ),
    );
  }

  List<BottomNavigationBarItem> _barItemList() {
    List<BottomNavigationBarItem> items = [];
    items.add(
      BottomNavigationBarItem(
        icon: Image.asset("assets/images/icons-home-32.png"),
        activeIcon: Image.asset("assets/images/icons-home-32-on.png"),
        label: "首页",
      ),
    );
    items.add(
      BottomNavigationBarItem(
        icon: Image.asset("assets/images/icons-hot-32.png"),
        activeIcon: Image.asset("assets/images/icons-hot-32-on.png"),
        label: "热点",
      ),
    );
    items.add(
      BottomNavigationBarItem(
        icon: Image.asset("assets/images/icons-user-32.png"),
        activeIcon: Image.asset("assets/images/icons-user-32-on.png"),
        label: "我的",
      ),
    );
    return items;
  }
}
